import { updateStorage } from './tools'
import request from '../utils/request'
let goodsInfo = localStorage.getItem('goodsInfo')
try {
    goodsInfo = JSON.parse(goodsInfo) || {}
} catch (err) {
    goodsInfo = {}
}

export default {
    // 启用命名空间
    namespaced: true,
    state: {
        goodsInfo,
    },
    getters: {
       

    },
    mutations: {
        //更新本地存储数据与state数据
        getGoodsInfo(state,payload){
            state.goodsInfo=payload
            updateStorage('goodsInfo',payload)
        }
       
    },
    actions: {
        async getGoodsData(context,payload){
            const { data } = await request.get("/getAllgoods", {
                params: payload,
            })
            context.commit('getGoodsInfo',data.data)
            return data
            
        }
       
    }
}